<%-- 
    Document   : goaddstu
    Created on : 2013-5-7, 21:26:08
    Author     : Sam.Zheng <zcl1866@sina.com>
--%>
<%String path = request.getContextPath();%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <c:import url="/resource/include/header.jsp" />
    </head>
    <form id="form">
    <body>
        <div style="margin-top: 20px;margin-left: 20px;">
            <div>
                <label for="name">学生姓名</label>
                <input class="easyui-validatebox" id="s_name"  name="name" 
                        data-options="required:true,validType:'length[3,8]',invalidMessage:'字符长度在3到8个字符',missingMessage :'学生姓名不能为空'"/>
            </div>
            <div  style="padding-top: 10px">
                <label for="className">选择年级</label>
                <select id="className" name="className" >
                    <option value="0">--选择--</option>
                    ${options}
                </select>
            </div>
            <div style="padding-top: 20px;text-align: center">
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()">保存</a>
                <a href="javascript:void(0)" class="easyui-linkbutton" onclick="closeDialog()">取消</a>
            </div>


        </div>
        <script>
            function submitForm(){
                var  classId =  $("#className").val();
                if(classId==0){
                    win.alert("警告", "请选择班级");
                    return ;
                }
                var s_name = $("#s_name").val();
                if(s_name==""){
                     win.alert("警告", "学生姓名不能为空");
                    return ;
                }
                var json = {name:s_name,s_class:{id:classId}};
                $.ajax({
                    type: "post",
                    url: "<%=path%>/app/index/addStudent/",
                    data:  $.toJSON( json ),
                    contentType: "application/json",//application/xml
                    success: function(msg){
                        if(msg == 1){
                            win.messageBox("恭喜", "保存成功", function(){location.reload()});
                            
                        }else{
                            win.messageBox("错误","保存失败");
                        }
                    }
                });
            }
            function closeDialog(){
                win.close("modfiyStu");
            }
          
        </script>
    </form>
    </body>
</html>
